<?php
//       PHPcongrats - Holiday and Birthday Mailer
//     
//    Copyright (C) 2011  Matthias Nass
//
//    This program is free software; you can redistribute it and/or modify it under the terms of the GNU General Public License as published by the Free Software Foundation; either version 3 of the License, or (at your option) any later version.
//
//    This program is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License for more details.
//
//    You should have received a copy of the GNU General Public License along with this program; if not, see <http://www.gnu.org/licenses/>.

session_start();

if ($_SESSION['loggedin'] == true){

     $_SESSION['savedName'] = $_POST['name'];
     $_SESSION['savedHoliId']  = $_POST['holiday_id'];
     $_SESSION['savedText']  = $_POST['text'];
     $_SESSION['savedLang'] = $_POST['lang'];
     $_SESSION['savedCount'] = $_POST['count'];
     
    if (($_POST['name']=='')){
     		$_SESSION['message'] = "Name ist leer!";
     		$location_to_jump = "Location: http:./textadd.php";
     		header( $location_to_jump );        
     }else{
             include "./DBconnect.php";
             $query = "INSERT INTO text VALUES(null,              
             ".(int) $_POST['holiday_id'].",
             '".mysql_real_escape_string($_POST['name'])."',
             '".mysql_real_escape_string($_POST['lang'])."',
             '".mysql_real_escape_string($_POST['text'])."',
             CURRENT_TIMESTAMP, CURRENT_TIMESTAMP,
             ". (int) $_POST['count'].");";   
             $result = mysql_db_query($database, $query, $link);
             mysql_close($link);
            if($result == false){
     		$_SESSION['message'] = $query;
     		$location_to_jump = "Location: http:./textadd.php";
     		header( $location_to_jump );          
             }else {
               $_SESSION['savedName'] = "";
               $_SESSION['savedHoliId']  = "";
               $_SESSION['savedLang']  = "";
               $_SESSION['savedText'] = "";
             $_SESSION['message'] = "Person gespeichert";
     		$location_to_jump = "Location: http:./text.php";
     		header( $location_to_jump );                       
             }    			
     }
} else{
	$_SESSION['last_location'] = "./textadd.php";
	header( 'Location: http:./login.php' );
}
?>